﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core
{
    public static partial class contest
    {
        public static dynamic getAutoCid()
        {
            var sql = new Sql.SqlDataContext();
            var result = from c in sql.Contest
                         orderby c.cid
                         select c.cid;
            int? first = result.FirstOrDefault();
            if (first == null)
            {
                return new
                {
                    cid = 1000,
                    success = true
                };
            }
            else
            {
                foreach (var c in result)
                {
                    if (c - first > 1)
                        break;
                    first = c;
                }
                return new
                {
                    cid = first + 1,
                    success = true
                };
            }
        }
    }
}
